package adv2;

import java.util.*;

public class MapTest {

	public static void main(String[] args) {
		// Map测试
		Map<String, String> m = new HashMap<String, String>();
		m.put("dog", "狗");
		m.put("cat", "猫");
		m.put("cow", "牛");
		m.put("cow", "水牛");
		m.put("mickymouse", null);// !!!!!!!!!

		// 通过equals来判断key是否重复
		// 如果重复，key不变，新值替换旧值
		System.out.println(m.size());
		System.out.println(m);
		Scanner in = new Scanner(System.in);
		System.out.println(">>>>>>>>>>>>>.");
		System.out.println("to be del");
		String del = in.next();
		String delValue = m.remove(del);
		System.out.println("被删除的value是" + delValue);
		System.out.println("删除后：" + m);
		System.out.println(">>>>>>>>>>>>>.");
		System.out.println("input a word:");
		String word = in.next();
		// String value = m.get(word);
		// if (value == null) {
		if (!m.containsKey(word)) {
			System.out.println("不存在此单词");
		} else {
			String value = m.get(word);
			System.out.println(word + "对应" + value);
		}
	}

}
